//
//  StatusCellBottomView.swift
//  MicroBlog
//
//  Created by 002 on 15/10/19.
//  Copyright © 2015年 002. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
// MARK:懒加载控件
    // 转发按钮
    private lazy var retweetedButton : UIButton = UIButton.init(title: "转发", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_retweet")
    // 评论按钮
    private lazy var commentButton : UIButton = UIButton.init(title: "评论", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_comment")
    // 点赞按钮
    private lazy var likeButton : UIButton = UIButton.init(title: "点赞", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_unlike")
    
}

extension StatusCellBottomView {

/// MARK:设置UI
    func setupUI() {
        
        // 0. 设置背景颜色
        backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        
        // 1->添加控件
        addSubview(retweetedButton)
        addSubview(commentButton)
        addSubview(likeButton)
        
        // 2->布局
        // 转发
        retweetedButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        
        // 评论
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(retweetedButton.snp_right)
            make.bottom.equalTo(retweetedButton.snp_bottom)
            make.width.equalTo(retweetedButton.snp_width)
        }
        
        // 点赞
        likeButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(commentButton.snp_right)
            make.height.equalTo(commentButton.snp_height)
            make.width.equalTo(retweetedButton.snp_width)
            make.right.equalTo(self.snp_right)
        }
        
        // 3->分隔视图(不使用计算性属性是因为在此会让人产生阅读成本)
        let sepView1 : UIView = sepView()
        let sepView2 : UIView = sepView()
        
        // 添加到已经布局好的上面3个Button上
        addSubview(sepView1)
        addSubview(sepView2)
        
        // 布局
        // 设置宽度和比例因子
        let w = 0.5
        let mutiple = 0.4
        
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedButton.snp_right)
            make.centerY.equalTo(retweetedButton.snp_centerY)
            make.height.equalTo(retweetedButton.snp_height).multipliedBy(mutiple)
            make.width.equalTo(w)
        }
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.centerY.equalTo(retweetedButton.snp_centerY)
            make.height.equalTo(retweetedButton.snp_height).multipliedBy(mutiple)
            make.width.equalTo(w)
        }
    }
    
    private func sepView() -> UIView {
        
        let sep = UIView()
        sep.backgroundColor = UIColor.lightGrayColor()
        return sep
    }
}
